﻿using System;
using System.Collections.Generic;
using System.Text;
using ProtoBuf;

namespace LingDong.IndexEntities.Dictionary
{
    [ProtoContract]
    [Serializable]
    public class InvertedListEntity : IComparable
    {
        #region Constructor

        private InvertedListEntity()
        {
        }

        public InvertedListEntity(int docID)
        {
            this.DocID = docID;
            this.TFInDoc = 0;
            this.HitList = new List<HitListEntity>();
        }

        public void AddHit(short senIndex, short termIndex, PanGu.POS pos, TermHTMLPosition position, int font)
        {
            TFInDoc++;
            HitList.Add(new HitListEntity(senIndex, termIndex, pos, position, font));
        }

        #endregion
        

        #region ToString
        
        public override string ToString()
        {
            StringBuilder hitListContent = new StringBuilder();
            foreach (HitListEntity hit in HitList)
            {
                hitListContent.AppendLine(hit.ToString());
            }
            return String.Format("DocID: {0}, TF: {1}, HitList: \n{2}",
                DocID, TFInDoc, hitListContent.ToString());
        }

        #endregion
        

        #region Feilds
        
        [ProtoMember(1)]
        public int DocID { get; set; }
        [ProtoMember(2)]
        public int TFInDoc { get; set; }
        [ProtoMember(3)]
        public List<HitListEntity> HitList { get; set; }

        #endregion
        

        #region IComparable Members

        public int CompareTo(object obj)
        {
            InvertedListEntity target = obj as InvertedListEntity;
            return this.DocID.CompareTo(target.DocID);
        }

        #endregion
    }
}
